package com.tangguangdi.base.db.generator.controller;


import com.tangguangdi.base.common.basic.Result;
import com.tangguangdi.base.db.generator.entity.CodeView;
import com.tangguangdi.base.db.generator.service.GeneratorService;
import com.tangguangdi.base.db.properties.GeneratorProperties;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 代码生成
 */
@RestController
@RequestMapping("/max-db/generator")
public class GeneratorController {

    @Resource
    private GeneratorService generatorService;

    /**
     * 配置信息
     * @return Map
     */
    @GetMapping
    public Result<Map> info() {
        return new Result<Map>()
                .setSuccess(true)
                .setData(generatorService.info());
    }

    /**
     * 代码预览
     * @param properties 生成参数
     * @return
     */
    @PutMapping
    public Result<List<CodeView>> view(@RequestBody GeneratorProperties properties) {
        return new Result<List<CodeView>>()
                .setSuccess(true)
                .setData(generatorService.view(properties));
    }

    /**
     * 代码生成
     * @param view 预览代码
     * @return Result
     */
    @PostMapping
    public Result<String> generate(@RequestBody List<CodeView> view) {
        generatorService.generate(view);
        return new Result<String>()
                .setSuccess(true)
                .setData("代码生成完毕");
    }

}
